import React, { Component } from 'react';
import { connect } from 'react-redux';
import { addgoods,deletegoods } from '../../actions/index';
import { Divider } from 'antd';

class Goods extends Component{
    constructor(){
        super();
        this.state={
            goodslist:[{name:'aaa',price:20},{name:'bbb',price:30},{name:'ccc',price:50}]
        }
    }
    componentWillMount(){
        console.log(this.props.tologin)
    }
    addgoods(data){
      this.props.addgoods({name:data,num:1})
    }
    deletegoods(data){
        this.props.deletegoods({name:data})
    }
    render(){
        let goodslist=this.state.goodslist.map(item=>{
            return(
                <div key={item.price}>
                <div>name:{item.name}</div>
                <div>price:{item.price}</div>
                <div style={{display:'flex'}}>
                <div style={{flex:1}} onClick={this.addgoods.bind(this,item.name)}>+</div>
                <div style={{flex:1}} onClick={this.deletegoods.bind(this,item.name)}>-</div>
                </div>
                </div>
            )
        })
        return(
            <div>
                {goodslist}
            </div>
        )
    }
}


const state=state=>{
    return({
        tologin:state.tologin,
        cart:state.cart
    })
}

export default connect(state,(dispatch)=>({
    addgoods(data){
      dispatch(addgoods(data))  
    },
    deletegoods(data){
        dispatch(deletegoods(data))
    }
}))(Goods)

